﻿/*!
 * Knockout+ Library v1.1.0
 * https://knockoutplus.codeplex.com/
 *
 * Copyright 2014 Janusz Noszczyński and other contributors
 * Released under the MIT license
 * https://knockoutplus.codeplex.com/license
 *
 * More documentation and examples
 * http://blog.coderiseventures.com/
 */

(function ($, ko)
{
    ko.bindingHandlers.drag =
    {
        init: function (element, valueAccessor, allBindingsAccessor, viewModel)
        {
            var $element = $(element);
            var value = valueAccessor();
            var options = value.options || {};

            options.start = function (event, ui)
            {
                if (value.isDragging)
                {
                    value.isDragging(true);
                }
            };

            options.stop = function (event, ui)
            {
                if (value.isDragging)
                {
                    value.isDragging(false);
                }
            };

            $element.draggable(options);
            $element.data('draggedObj', viewModel);
        }
    };

    ko.bindingHandlers.drop =
    {
        init: function (element, valueAccessor, allBindingsAccessor, viewModel)
        {
            var $element = $(element)
            var value = valueAccessor();
            var options = value.options || {};
            $element.droppable(options);
        }
    };
})
(jQuery, ko);